package com.mdjnu.mapper;

import com.mdjnu.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {
    /**
     * 查询所有用户
     * @return 用户列表
     */
    @Select("select * from Users")
    List<User> selectAll();
    /**
     * 根据邮箱和密码查询用户
     * @param email 邮箱
     * @param password_hash 密码
     * @return 用户
     */
    @Select("select * from Users where email=#{email} and password_hash=#{password_hash}")
    User findByEmailAndPassword(String email,String password_hash);

    /**
     * 更具邮箱查询用户
     * @param email 邮箱
     * @return 用户
     */
    @Select("select * from Users where email= #{email}")
    User findByEmail(String email);

    //List<User> in int[] userIds

    /**
     *  根据关注id查询用户
     * @param userIds
     * @return
     */
    @Select("<script>" +
            "SELECT user_id,username,avatar_url,user_level,vip_status FROM Users " +
            "WHERE user_id IN " +
            "<foreach item='userId' collection='array' open='(' separator=',' close=')'>" +
            "#{userId}" +
            "</foreach>" +
            "</script>")
    List<User> findByFollowId(int[] userIds);
}
